package com.lzh.runke.core.entity.validator;

import com.lzh.runke.core.entity.validator.annotation.Phone;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author LiuZiHao
 * @date 创建时间:2023年07月24日 11:08:21
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {
    @Override
    public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(str)) {
            return true;
        }
        return str.matches("^0?(13[0-9]|14[57]|15[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$");
    }
}
